package 获取锁对象;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket2 implements Runnable {
	int tickte=100;
	Lock lo=new ReentrantLock();
	@Override
	public void run() {
       while(true) {
    	   if(tickte==0) {
    		   System.out.println("票卖完了");
    		   break;
    	   }lo.lock();
    	   if( tickte>0) {
    		   try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	   }System.out.println(Thread.currentThread().getName()+"正在卖票"+tickte--);
       }lo.unlock();		
	}
	
	

}
